import time
from common.base import Base, get_driver
from selenium.webdriver.common.by import By

class AddressListPage(Base):

    #新增
    def clicl_theFrom(self):
        self.click((By.LINK_TEXT ,'收货地址'))
    #选择区域
    def choose_pro(self,content):
        self.click((By.XPATH,content))

    def choose_cuntry(self,content):
        self.click((By.XPATH,content))

    def choose_district(self,content):
        self.click((By.XPATH, content))

    def input_name(self,locator,content):
        self.send_keys((By.ID,locator),content)

    def input_emaill(self,locator,content):
        self.send_keys((By.ID,locator),content)

    def input_addr(self,locator,content):
        self.send_keys((By.ID,locator),content)

    def click_submit(self,locator):
        self.click((By.CLASS_NAME,locator))

    def input_tel(self,locator,content):
        self.send_keys((By.ID,locator),content)


    #修改
    def change_addr(self):
        self.click((By.XPATH,'//input[@value="张三"]'))

    def delete_addr(self):
        self.clear_addr((By.XPATH,'//input[@value="张三"]'))

    def add_name(self,content):
        self.send_keys((By.XPATH,'//input[@value="张三"]'),content)

    def click_submit1(self):
        self.click((By.CLASS_NAME,'bnt_blue_1'))









if __name__ == '__main__':
    #增加
    driver=get_driver()
    # driver.get('http://localhost:8080/ecshop/user.php?act=address_list')
    driver.get('http://localhost:8080/ecshop/user.php?act=address_list')
    time.sleep(3)
    address=AddressListPage(driver)
    address.clicl_theFrom()
    time.sleep(2)
    address.choose_pro('//select[@id="selProvinces_0"]/option[@value="24"]')
    time.sleep(1)
    address.choose_cuntry('//select[@id="selCities_0"]/option[@value="271"]')
    address.choose_district('//select[@id="selDistricts_0"]/option[@value="2715"]')
    address.input_name("consignee_0",'张三')
    address.input_emaill("email_0",'145111111@qq.com')
    address.input_addr("address_0",'四川省成都市温江区')
    address.input_tel('tel_0','1463215111')
    address.click_submit('bnt_blue_2')


    # 删除
    # address.click((By.XPATH, '//input[@name="button"]'))
    # driver.switch_to.alert.accept()


    #修改
    # address.change_addr()
    # address.delete_addr()
    # address.add_name('李四')
    # address.click_submit1()






